<?php

/**
 * 优惠用户管理
 * @author Ice <iceinto@mallog.com.cn>
 */
class LimitedUsersModel extends BaseModel
{
    /**
     * 获取领取用户数量
     * @param array $map 查询条件
     * @return int
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function getUsersCount($map)
    {
        return $this->where($map)->count();
    }

    /**
     * 获取领取用户数量
     * @param array $map 查询条件
     * @return array
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function getUsers($map)
    {
        return $this->where($map)->select();
    }

    /**
     * 获取当天领取用户数量
     * @param int $lid 优惠标示
     * @return array
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function dayUsersCount($lid)
    {
        //处理时间
        $date = new Date();
        $startTime = $date->format('%Y-%m-%d');
        $date = $date->dateAdd(1, 'd');
        $endTime = $date->format('%Y-%m-%d');
        $startTime = strtotime($startTime);
        $endTime = strtotime($endTime);
        //进行查询
        $map = array();
        $map['lid'] = $lid;
        $map['create_time'] = array(array('egt', $startTime), array('lt', $endTime), 'and');
        return $this->where($map)->count();
    }

    /**
     * 查询用户领取信息
     * @param int $uid 用户标示
     * @param int $lid 优惠标示
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function checkUserReceiveCount($uid, $lid)
    {
        $map = array();
        $map['lid'] = $lid;
        $map['uid'] = $uid;
        return $this->where($map)->count();
    }

    /**
     * 进行验证码验证
     * @param string $verify 验证码
     * @return array
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function checkVerify($verify)
    {
        $map = array();
        $map['verify'] = $verify;
        return $this->where($map)->find();
    }

    /**
     * 进行验证码验证
     * @param string $verify 验证码
     * @return array
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function getReceiveUsersCount($lid)
    {
        $map = array();
        $map['lid'] = $lid;
        $map['status'] = 2; //已经领取的数量
        return $this->where($map)->count();
    }
}